package com.randy.riolis.kontrakan;

import java.util.ArrayList;
import java.util.List;

import com.randy.riolis.kontrakan.adapter.KontrakanAdapter;
import com.randy.riolis.kontrakan.entity.Kontrakan;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MainActivity extends ActionBarActivity implements
		OnItemClickListener {

	private ListView lv;
	private KontrakanAdapter adapter;
	private List<Kontrakan> listKontrakan;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		lv = (ListView) findViewById(R.id.listKontrakan);

		setDataDummy();

		adapter = new KontrakanAdapter(this, listKontrakan);
		lv.setAdapter(adapter);

		lv.setOnItemClickListener(this);
	}

	private void setDataDummy() {
		// TODO Auto-generated method stub
		listKontrakan = new ArrayList<Kontrakan>();

		Kontrakan kontrakan1 = new Kontrakan();
		kontrakan1.setAlamat("Alamat 1");
		kontrakan1.setHarga("Rp 10.000.000 per tahun");
		kontrakan1.setGambar(R.drawable.kontrakan1);

		Kontrakan kontrakan2 = new Kontrakan();
		kontrakan2.setAlamat("Alamat 2");
		kontrakan2.setHarga("Rp 6.000.000 per tahun");
		kontrakan2.setGambar(R.drawable.kontrakan2);

		listKontrakan.add(kontrakan1);
		listKontrakan.add(kontrakan2);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
		// TODO Auto-generated method stub
		Bundle b = new Bundle();
		b.putString("alamat", ((Kontrakan) adapter.getItem(pos)).getAlamat());
		b.putString("harga", ((Kontrakan) adapter.getItem(pos)).getHarga());

		Intent i = new Intent(this, DetailActivity.class);
		i.putExtras(b);
		startActivity(i);
	}
}
